package com.fneuch.w40k;

import java.util.Locale;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

@Configuration
public class AppConfig {

	// Resolve logical view names to .jsp resources in the /WEB-INF/views directory
	@Bean
	ViewResolver viewResolver() {
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setViewClass(JstlView.class);
		resolver.setPrefix("/WEB-INF/views/jsp/");
		resolver.setSuffix(".jsp");
		return resolver;
	}
	
	@Bean
	ResourceBundleMessageSource messageSource() {
		ResourceBundleMessageSource messageBundle = new ResourceBundleMessageSource();
		
		messageBundle.setBasename("com.fneuch.w40k.libelle");
		
		return messageBundle;
	}
	
	@Bean
	SessionLocaleResolver localeResolver() {
		SessionLocaleResolver resolver = new SessionLocaleResolver();
		
		resolver.setDefaultLocale(Locale.CANADA_FRENCH);
		
		return resolver;
	}
	
	@Bean
	LocaleChangeInterceptor localeChangeInterceptor() {
		return new LocaleChangeInterceptor();
	}
	
	@Bean 
	ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() {		
		return new ControllerClassNameHandlerMapping();
	}
		
//	@Bean
//	PropertyPlaceholderConfigurer propertyConfigurer() {
//		
//		PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//		ClassPathResource cpr = new ClassPathResource("com/fneuch/w40k/mathammer_fr.properties");
//		
//		ppc.setLocation(cpr);
//		return ppc;
//	}

	
	
	@Bean
	LocalValidatorFactoryBean validator() {
		LocalValidatorFactoryBean lvfb = new LocalValidatorFactoryBean();
		return lvfb;
	}	
	
}
